/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package courseScheduler;

import java.sql.Connection;

/**
 *
 * @author david
 */
public class MainThread implements java.lang.Runnable {
    
    public MainFrame LoginFrame,AdminFrame,StudentFrame,FacultyFrame;

    private java.sql.Connection conn;
    private int id;
    private String type;

    public void run(){
        LoginFrame =  new MainFrame(new LoginPanelOne(this),true);
    }

    public static void main(String [] args){
        java.awt.EventQueue.invokeLater(new MainThread());
    }

    public void setConnection(java.sql.Connection newConn){
        conn = newConn;
    }

    void logOn(Connection connection,String newType, int newID) throws java.sql.SQLException{
        setConnection(connection);
        type = newType;
        id = newID;
        if (type.startsWith("f")){
            showFaculty();
        }
        else if (type.startsWith("a")){
            showAdmin();
        }
        else {
            showStudent();
        }
    }

    private void showStudent() {
        StudentFrame = new MainFrame(new StudentPanel(this),true);
    }

    private void showFaculty() {
        FacultyFrame = new MainFrame(new EmployeePanel(this),true);
        //FacultyFrame.compute();
    }

    private void showAdmin(){
        AdminFrame = new MainFrame(new AdminPanel(this),true);
    }

    public int getID(){
        return id;
    }

    public void setID(int newID){
        id = newID;
    }

    public java.sql.Connection getConn(){
        return conn;
    }
}
